<?php



/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
 
class Game_Form_Admin_Setting_Autopost extends Engine_Form
{
  public function init()
  {
    $this
      ->setTitle('Mochi Auto Post')
      ->setDescription('The Mochi Auto Post feature allows you to add a game to your site with a single click. By enabling this feature on your site, you\'ll be able to browse the Mochi Game Distribution catalog of games and click "add to my site". This will send all the important game data via the Mochi API to your site for the plugin to import the game automatically.');
    

    $this->addElement('Text', 'autoposturl', array(
      'label' => 'Auto Post URL',
      'description' => 'In order for Mochi to communicate with your site, you must login to your Mochi account, go to Mochi\'s Publisher Settings page, under "Auto Post Settings" section, update the "Auto Post URL" field with the URL you see in box below:',
      'disabled' => true,
      'readonly' => true,
      'ignore' => true,
      'style' => "width: 400px"
    )); 
      
    $this->addElement('Radio', 'enabled', array(
      'label' => 'Auto Post Enabled?',
      'description' => 'Would you like to enable Mochi Auto Post feature? Do NOT forget to update the "Auto Post URL" field under "Auto Post Settings" in your Mochi\'s Publisher Settings page.',
      'multiOptions' => array(
        '1' => 'Yes, enable this feature',
        '0' => 'No, disable this feature',  
      ),
      'validators' => array(
        new Engine_Validate_Callback(array($this, 'validateEnabled')),
      ),       
    ));

    
    $this->addElement('Select', 'gamestatus', array(
      'label' => 'Default Game Status',
      'description' => 'Please select default status games would have when imported. Only games with "Published" status will be viewable by your members. You can set status to "Pending", and then manually review games prior publishing them.',
      'value' => Game_Model_Game::STATUS_PENDING,
      'multiOptions' => Game_Form_Helper::getStatuses(),
    ));      

    $this->addElement('Radio', 'downloadswf', array(
      'label' => 'Download SWF File',
      'description' => 'Would you like to download SWF game file and save them on your server? With average of few hundred KB per file, storing game files may use a lot of your server space and slow down import process, so only download them if neccessary. Please note that in order to earn money with MochiAds, you will need to host the game\'s SWF file on your own server, and verify your domain in Mochi\'s Publisher settings on Mochi website. Recommend you to only check YES when importing Mochi games with "Published" status, and want to earn money with MoneyAds. Some games may NOT work (black-screen) if you host it on your server, in such case, you must use hot-link method. You can always manually download SWF files later on "View Games" page whenever you want to.',
      'multiOptions' => array(
        0 => 'No, hot-linked game SWF file from distributor',
        1 => 'Yes, download and store game SWF file on server' 
      ),
      'value' => 0,
    ));
    
    $this->addElement('Radio', 'downloadphoto', array(
      'label' => 'Download Photo File',
      'description' => 'Would you like to download game photo file and save them on your server? If game distributor allow you to hot-link photo files (most are), then you do NOT need to download game photo file. Hot-linked files allow you to save server space / bandwidth.',
         
      'multiOptions' => array(
        0 => 'No, hot-linked game photo file from distributor',
        1 => 'Yes, download and store game photo file on server' 
      ),
      'value' => 0,
    ));    
    
    // Add submit button
    $this->addElement('Button', 'submit', array(
      'label' => 'Save Changes',
      'type' => 'submit',
      'ignore' => true
    ));
  }
  
 
  
  public function validateEnabled($value)
  {
    $publisherid = Engine_Api::_()->getApi('settings', 'core')->getSetting('game.mochipublisherid');
    if ($value && empty($publisherid)) {
      $this->enabled->getValidator('Engine_Validate_Callback')->setMessage('Mochi Publisher ID is required in order to enable this feature. Please go to Global Settings page to update this field.');
      return false;
    }

    return true;
  }   
  
}